﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_Package_NewPackageType : AdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        

        if (isLogin())
        {
            if (LoginedStaff.tblRole.Role != "Admin")
                Response.Redirect("~/Admin/Index.aspx");
        }
        else
        {
            Response.Redirect("~/Admin/Stafflogin.aspx");
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        nameLabel.Visible = false;
        feeLabel.Visible = false;
        decimal dd;
        bool feeCheck = Decimal.TryParse(AdditionalFee.Text, out dd);
        if (string.IsNullOrEmpty(AdditionalFee.Text) || Convert.ToDecimal(AdditionalFee.Text) <= 0)
        {
            feeCheck = false;
        }
        if (!string.IsNullOrEmpty(ParcelType.Text) && feeCheck)
        {
            MailDistributionSystemDBDataContext db = new MailDistributionSystemDBDataContext();
            if (db.tblParcelTypes.Where(c => c.ParcelType == ParcelType.Text.Trim()).Count() == 0)
            {
                tblParcelType parcel = new tblParcelType();
                parcel.ParcelType = ParcelType.Text.Trim();
                parcel.AdditionalFee = Convert.ToDecimal(AdditionalFee.Text);
                db.tblParcelTypes.InsertOnSubmit(parcel);
                db.SubmitChanges();
                Response.Redirect("~/Admin/ParcelType/ViewParcelType.aspx");
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Parcel Type Already Exist!')", true);
            }
        }
        else
        {
            if (string.IsNullOrEmpty(ParcelType.Text))
            {
                nameLabel.Visible = true;
            }
            if (!feeCheck)
            {
                feeLabel.Visible = true;
            }
        }
    }
    protected void ParcelType_TextChanged(object sender, EventArgs e)
    {

    }
}